/*
*
* A simple XmlHTTPRequest wrapper
*
*/

function Ajax(){
	if(!window.XMLHttpRequest) XMLHttpRequest = function() {
		try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(e){}
		try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(e){}
		try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(e){}
		try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}
		throw new Error("No XMLHttpRequest object available.")
	};
	var xmlHttp = new XMLHttpRequest();
	this.getXmlHttp = function(){return xmlHttp;}
}

Ajax.prototype.send = function(url, params, onsuccess, onfailure){	
	var request = this.getXmlHttp();
	
	var param_str = "";
	for(var key in params)
		param_str += (param_str ? "&" : "") + key + "=" + params[key];
	
	request.open(param_str ? "POST" : "GET", url, true);
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	request.onreadystatechange = function() {
		if (request.readyState == 4)
		{
			if(request.status == 200)
				onsuccess && onsuccess(request.responseText);
			else
				onfailure && onfailure(request.status, request.statusText);
		}
	};
	
	request.send(param_str);
}
